<script>
import API from "./api";
import baseLogin from "@/view/login/login";
import i18n from "./locale";
import loginIcon from "@/assets/images/logo-icon.png";
export default {
  extends: baseLogin,
  data() {
    return {
      i18n: i18n,
      showTip: true,
      loginIcon: loginIcon
    };
  },

  methods: {
    handleSubmit() {
      let tthis = this;
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          let userID = this.formInline.userName,
            userPwd = this.formInline.password,
            userSrc = "web";
          if (!this.loading) {
            this.loading = true;
            API.login({ userID, userPwd, userSrc })
              .then(res => {
                setTimeout(function() {
                  tthis.loading = false;
                }, 1000);
                if (res) {
                  const data = res.data;
                  this.$store.commit("setToken", data.userName);
                  this.$store.commit("setAccess", data.access.toString());
                  this.$store.commit("setUserInfo", data);
                  this.goToNext();
                }
              })
              .catch(err => {
                setTimeout(function() {
                  tthis.loading = false;
                }, 1000);
                if (err.msg) {
                  this.$Message.error({
                    duration: 2,
                    content: err.msg
                  });
                } else {
                  this.$Message.error("服务内部错误");
                }
              });
          }
        }
      });
    },

    goToNext() {
      this.$router.push({
        name: "home"
      });
    }
  }
};
</script>
<style lang="less" scoped>
.login {
  .qrcode {
    width: 100px;
    height: 100px;
    margin: auto;
    .android {
      background-image: url("../../assets/images/android.png");
      background-repeat: no-repeat;
      background-position: center;
      background-size: 100% 100%;
      width: 90px;
      height: 90px;
    }
    position: relative;
  }
}
</style>
